/* eslint-disable camelcase,@typescript-eslint/no-unused-vars */ // DO NOT EDIT THIS FILE. AUTO-GENERATED BY mobiletto-orm-typedef-gen import { H3Event, H3Error } from "h3"; import { AccountTypeDef } from "yuebing-model"; import { MobilettoOrmSyncError } from "mobiletto-orm-typedef"; export default defineEventHandler(async (event: H3Event) => { return await filterErrors(event, "account.delete", async (event: H3Event) => { return await requireAccountObject(event, "account.delete", async (event: H3Event, session, account) => { const accountRepo = accountRepository(); const id = event?.context?.params?.id; if (!id) throw notFound(accountRepo.typeDef.idFieldName()); try { const account_by_id = await accountRepo.safeFindById(id); if (account_by_id) { if (!account.admin && account_by_id.account !== session.account) throw forbidden(); if (typeof AccountTypeDef.apiConfig.delete?.validate === "function") { const validated = await AccountTypeDef.apiConfig.delete.validate(account, account_by_id); if (validated === true || (typeof validated === "object" && Object.keys(validated).length === 0)) { // successfully validated } else if (typeof validated === "object" && Object.keys(validated).length > 0) { throw validationError(validated); } else { throw validationError({global: ["validation"]}); } } return await accountRepo.remove(account_by_id); } } catch (e) { if (e instanceof H3Error) throw e; if (e instanceof MobilettoOrmSyncError) { logger.warn(`account.delete: sync error: ${e}`); throw conflict(); } logger.error(`account.delete: unexpected error: ${e}`); throw serverError(); } throw notFound(id); }); }); });